package gowcage.testandroid.RecyclerView;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.View;
import android.widget.Toast;

import com.gowcage.testandroid.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/4/10.
 */

public class RecyclerViewActivity extends Activity {

    //BindViews-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
//    @BindView(R.id.recycler_recyclerView)
    RecyclerView recycler;
    //BindViews-----------------------------------------------------------------------------------------------------------------------------------------------------------------------

    private RecyclerAdapter adapter;
    private List<String> data;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recyclerview);
        initData();
        recycler = (RecyclerView) findViewById(R.id.recycler_recyclerView);

        //线性布局管理器
//        recycler.setLayoutManager(new LinearLayoutManager(this));//默认垂直
//        recycler.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));//水平，最后一个参数代表反向布局
//        recycler.setLayoutManager(new GridLayoutManager(this,4));//表格布局管理局器，4列
        recycler.setLayoutManager(new StaggeredGridLayoutManager(4, DividerItemDecoration.VERTICAL_LIST));

        adapter = new RecyclerAdapter(this, data);

//        recycler.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.HORIZONTAL_LIST));//不适用于gridlayout,横向布局时divider会被item的背景遮掉
//        recycler.addItemDecoration(new DividerItemDecoration(this,DividerItemDecoration.HORIZONTAL_LIST));
        recycler.addItemDecoration(new DividerGridItemDecoration(this));//水平分隔线出不来
//        recycler.addItemDecoration(new SimpleDecoration());

        adapter.setOnItemClickListener(new RecyclerAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View v, int position) {
                Toast.makeText(RecyclerViewActivity.this, position + " click",Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onItemLongClick(View v, int position) {
                Toast.makeText(RecyclerViewActivity.this, position + " long click",Toast.LENGTH_SHORT).show();
            }
        });
        recycler.setAdapter(adapter);
    }

    private void initData() {
        data = new ArrayList<String>();
        for (int i = 'A'; i <= 'z'; i++) {
            data.add("" + (char) i);
        }
        /*for (int i = 'a'; i <= 'z'; i++) {
            data.add("" + (char) i);
        }*/
    }
}
